Jim's example of creating an interactive plot to adjust dimensions of a single Gaussian


In [18]:
import matplotlib.pyplot as plt 
import numpy as np

from IPython.html import widgets
from IPython.html.widgets import interact
from IPython.display import display

In [16]:
mean=0
sigma=1
x=np.linspace(-6,6,500)
y=(1/sigma/np.sqrt(2*np.pi))*np.exp(-(x-mean)**2/2/sigma**2)

%matplotlib inline
fig = plt.figure(figsize=(4,4))
axes = fig.add_subplot(111)
axes.plot(x,y)


Out[16]:
[<matplotlib.lines.Line2D at 0x108e525d0>]

In [19]:
def plt_arrays(x, y, title="title", color="blue", linestyle="solid", linewidth=2):
    fig = plt.figure()
    axes = fig.add_subplot(111)
    axes.plot(x,y, color=color, linestyle=linestyle, linewidth=linewidth)
    axes.set_title(title)
    axes.grid()
    plt.show()

In [31]:
def f(sigma, mu, **kwargs): 
    x=np.linspace(-6*sigma+mu,6*sigma+mu,500)
    y=(1/sigma/np.sqrt(2*np.pi))*np.exp(-(x-mu)**2/2/sigma**2)
    plt_arrays(x,y,title="title", **kwargs)

In [28]:
sigma=1
mu=0
f(sigma, mu)



In [32]:
i = interact(f, sigma=(0.001,5),mu=(-10,10),color = ["red","blue","green"],linestyle=["solid","dashed"],linewidth=(1,5))



In [ ]: